package server.config.swagger;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Value("${host}")
    String host;
    @Value("${swagger}")
    boolean swagger;

    @Bean
    public Docket createRestApi() {
        Docket bulid = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).enable(swagger);
        return bulid.host(host).
                select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any()).build();
    }

    /**
     * api文档的详细信息函数,注意这里的注解引用的是哪个
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("sfex矿场 API")
                .version("1.0")
                .description("API 描述")
                .license("1.0")
                .build();
    }
}
